#ifndef __RAD__
#define __386__
#include "rad.h"
#endif

#define __XENON_H__

#define HUD_MESSAGE_LEN 128
#define SCREENBUFFERSIZE (128*1024)
#define SAVESCREENBUFFERSIZE (352*200)
#define SAFEAREA 12000
typedef signed short BOOL;

#ifndef NUMSPRITECHANNELS
#define NUMSPRITECHANNELS 16
#endif

// A list of the basic filenames for each scene
#define  VID_LGSLOGO      0
#define  VID_VMILOGO      1
#define  VID_FWINTRO1     2
#define  VID_FWINTRO2     3
#define  VID_BLOODHEAD    4
#define  VID_CHICKENS     5
#define  VID_PONG         7
#define  VID_PITIFUL      8
#define  VID_POSEND       9
#define  VID_NEGEND       10
#define  VID_CREDITS      11
#define  VID_POEMS        12
#define  VID_WINOVER      13
#define  VID_LOSEOVER     14

//#define g_cdrom "k\:\\FIRE_PC"
#ifdef _XENON_
// ----------------------------------------------------------------
//    Global Variables
// ----------------------------------------------------------------
char  g_cutname[50];
char  g_curname[50];
char  g_gameplaying   = FALSE;
char  g_switched      = FALSE;
char  g_textcol       = SHOTCOLOR +1;
char *g_still         = (char *) NULL;
char *g_stillpalette  = (char *) NULL;
char g_secrroomsolved = FALSE;
char g_restoregame    =MAX_SAVEDGAMES;
extern TARGET *g_SpritesOnScreen;
extern char	*g_eventspace;
short g_damagedchannel= -1;
long g_restoreframe=-1;
long g_radmallocfail=0;
char g_killgame    =FALSE;
char g_leavegame   =FALSE;
char g_killscene   =FALSE;
char g_pauseon     =FALSE;
char g_entirepanel =TRUE;
char g_godpower    =FALSE;
char g_typeofdeath =MAX_DEATHS;
long g_videotoplay=-1;
long g_numberofframes=-1;
char g_incyberspace = FALSE;
char g_selectedtool,g_selectedweap;
long g_currentscenenumber=0,g_nextscenenumber=0;
long g_dethframe  =-1; /*Beginning of death cutscene*/
long g_ecutframe  =-1; /*Beginning of exit  cutscene*/
long g_branchframe=-1; /*A frame to branch to*/
long g_playerdead =FALSE;
long g_endcut =-1; // end of cut scene
long debugSpeed=0;
long startTime;
long endTime;
long frames=0;
short g_didloop=FALSE;
short g_looptime;
char g_cdrom[4];
u8 g_gotsound=FALSE;

u8 *databuf;
u8 *smackBuffer,*smackBuffer2;

// Keep track of which sprite channels are active or inactive
long g_channelstate[NUMSPRITECHANNELS]= { 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0 };

long g_targetgroup=1;   // Which target group (if any) is active
long g_curframe;            // Current frame of the scene
long g_curscene=0;
long g_savescene=0;

long g_seekto=0;            // Set this to seek within a scene
extern long g_inputdevice;      /* User input device in use */
JOYDATA g_joydata;      // holds joystick data if any
long g_scenentry[12];  // how many times thru scene - for dependencies.

char g_stilltextcols[11] =
 {
  215,
  234,
  249,
  210,
  116,
  35,
  248,
  234,
  115,
  255,
  152
 };


char *g_scenenames[12] = 
{
	"COASTAL",            //#0   Jack
	"CANYON",             //#1   Jack
	"GREAT WALL",         //#2   Xiang
	"PORTAL",             //#3   Jack
	"INFONET",            //#4   Xiang
	"CITY OF LIGHT",      //#5   Neo
	"DATA CLEANSING",     //#6   Jack
	"PERIMETER DEFENSE",  //#7   Xiang
	"FIREWALL",           //#8   Xiang
	"INWALL",             //#9   Neo
	"FINAL CONFRONTATION" //#10  Neo
};

long g_scenelength[11] = 
{
	1265, //coastal
	1990, //canyon
	2049, //gwall
	 993, //portal
	1243, //infonet
	1182, //col
	1811, //dc
	2195, //pd
	1551, //firewal
	1190, //inwall
	1207, //fcon
};

// A list of the basic filenames for each scene
char g_scenetable[][12] = 
{
	"coastal",      //#0   Jack
	"canyon",       //#1   Jack
	"gwall",        //#2   Xiang
	"portal",       //#3   Jack
	"infonet",      //#4   Xiang
	"col",          //#5   Neo
	"dc",           //#6   Jack
	"pd",           //#7   Xiang
	"firewal",      //#8   Xiang
	"inwall",        //#9  Neo
	"fcon" ,        //#10  Neo
	"gendeath",     //#12  Osman
	"pause",        //#13 
	"options",      //#14
	"save",         //#15
	"credits",      //#16
	"clue",         //#17
};

// below are opening cut scenes
char g_introtable[][12] = 
{
	"coopen",   //#0    coastal
	"",         //#1    canyon
	"",         //#2    greatwall
	"poopen",   //#3    portal
	"inopen",   //#4    infonet
	"ciopen",   //#5    city of light
	"",         //#6    data cleans
	"",         //#7    perimeter
	"fwopen",   //#8    firewall
	"iwopen",   //#9    within the wall
	"fcopen",   //#10   final confrontation
	""               
};

//below are 
char g_cutscenes[][32] =
{
/*0*/ "\\data\\coexit.smk",     // coastal good exit
/*1*/ "\\data\\codie1.smk",     // coastal only death scene (fall)
/*2*/ "\\data\\caexit.smk",     // canyon good exit into rebel base (caz)
/*3*/ "\\data\\cadie2.smk",     // canyon death crash into ground (cav)
/*4*/ "\\data\\cadie1.smk",     // canyon death crash into mountain (cay)
/*5*/ "\\data\\gwdie1.smk",     // gwall death 1 near great wall (gwy) (1st 400 frames..)
/*6*/ "\\data\\gwdie2.smk",     // gwall death 2 fortress death (gwz)
/*7*/ "\\data\\podie1.smk",     // portal only death scene NO SPECIAL EXIT! (pody)
/*8*/ "\\data\\inexit.smk",     // infonet good exit (inw)
/*9*/ "\\data\\indie1.smk",     // infonet only death scene (inz)
/*10*/"\\data\\ciexit.smk",     // city of light good exit (clenew)
/*11*/"\\data\\cidie1.smk",     // city of light only death scene (clz)
/*12*/"\\data\\dcdie1.smk",     // data cl death by deleter (deleter)
/*13*/"\\data\\dcdie2.smk",     // data cl death in icon hallway (dscrash)
/*14*/"\\data\\dcdie3.smk",     // data cl death by missle (missle)
/*15*/"\\data\\dcdie4.smk",     // data cl death in secret room (secret)
/*16*/"\\data\\dcdie5.smk",     // data cl death by doggy (tracedog)
/*17*/"\\data\\peexit.smk",     // perim good exit (pev)
/*18*/"\\data\\pedie1.smk",     // blast door (peu)
/*19*/"\\data\\pedie2.smk",     // wide trench (pew)
/*20*/"\\data\\pedie3.smk",     // perim laser gate death (pex)
/*21*/"\\data\\pedie4.smk",     // perim narrows death ?? (pey)
/*22*/"\\data\\pedie5.smk",     // perim killing fields (big screws) death (pez)
/*23*/"\\data\\fwdie1.smk",     // firewall low death (fwx)
/*24*/"\\data\\fwdie2.smk",     // firewall upper death (fwy)
/*25*/"\\data\\iwexit.smk",     // any special exit for InWall?
/*26*/"\\data\\iwdie1.smk",     // cut scenes for InWall?
/*27*/"\\data\\iwdie2.smk",     // cut scenes for InWall?
/*28*/"\\data\\iwdie3.smk",     // cut scenes for InWall?
/*29*/"\\data\\fcexit.smk",     // Any special exit for Final Con? (fcf)
/*30*/"\\data\\fcdie1.smk",     // final conflict death by the clap (clop)
/*31*/"\\data\\fcdie2.smk",     // final conflict death by shot (boom)
/*32*/"\\data\\newdead.smk",    // this is the generic death scene
/*33*/"\\data\\poexit.smk",     // last minute add on - portal good exit
/*34*/"\\data\\iwdie4.smk"      // last minute, death by tornado in Inwall
};

char g_videotable[][32] = 
{
	"\\data\\lg.smk",       //0     
	"\\data\\vmilogo.smk",  //1
	"\\data\\fireint1.smk", //2
	"\\data\\fireint2.smk", //3
	"\\data\\bloodhed.smk", //4
	"\\data\\chickens.smk", //5
	"\\data\\foundus.smk",  //6
	"\\data\\pong.smk",     //7
	"\\data\\pitiful.smk",  //8
	"\\data\\posend.smk",   //9
	"\\data\\negend.smk",   //10
	"\\data\\credits.smk",  //11
	"\\data\\poems.smk",    //12
    "\\data\\winover.smk", //13
    "\\data\\loseover.smk" //14
};                                                      

Smack *smk, *smkcut,*g_smkscene,*g_smkintro;
// Sprites to be pasted into the scene (by channel).  Includes coords.
blitpic g_panel  =  {0,0,0,NULL,NULL};// Structure for the control panel
blitpic g_helth  =  {0,0,0,NULL,NULL};// Structure for the heath bar
blitpic g_lives  =  {0,0,0,NULL,NULL};// Structure for the lives bar
blitpic g_damg   =  {0,0,0,NULL,NULL};// Structure for the damage ani
u8 g_getpanelpalette=FALSE;
u8 *g_collisionmap=0;

char g_hudmessage[HUD_MESSAGE_LEN]; // A HUD (heads-up) message to be put on the screen
long    g_hudtimer=0;       // How many frames the HUD message will be displayed
char g_buffer[256];
extern u8 *g_spritebuf;
// ------------------------------------------------------------
//    Function Definitions
// ------------------------------------------------------------
void FWSaveGame();

void inittoolsweaps(void);
playStill(char *basename);

playScene(char *basename,u8 *databuf,u8 *smackbuffer,u8 *smackbuffer2);
processSprites(u8 *databuf,u8 *smackerbuf);
pasteApplicableSprites(u8 *smackerbuf);
copyBufferToBuffer(u8 *buf1,u8 *buf2);
u8 *alignTo4(u8 *ptr);
pastToBuffer(u8 *to,u8 *from,long width,long height);
updatePanel(u8 *smackbuffer);
loadConfiguaration();
loadTurnData(char *name);
void usePlayer(char * smkfile);

#else

extern char  g_secrroomsolved;
extern char *g_scenenames[];
extern char g_hudmessage[HUD_MESSAGE_LEN];      

extern long g_curscene;

extern long g_channelstate[NUMSPRITECHANNELS];
extern long g_seekto;
extern long g_newscene;         // Set this to switch scenes
extern long g_targetgroup;      // Which target group (if any) is active
extern long g_scenentry[12];  // how many times thru scene - for dependencies.
extern u8 g_gotsound;

extern long debugSpeed;
extern long debugSpeed;
extern long g_curframe;
extern u8 *smackbuffer,*smackBuffer2;
extern int processSprites(u8 *databuf,u8 *smackerbuf);
extern void closeFirewall();
extern char g_pauseon;
extern char g_restoregame;
extern long g_restoreframe;
extern char g_killgame;
extern char g_leavegame;
extern char g_killscene;
extern char g_buffer[256];
extern char g_cdrom[4];
extern char g_selectedtool,g_selectedweap;
extern char g_switched;
extern long g_scenelength[11]; 
extern long g_videotoplay;
extern char g_textcol;
extern char g_switched;
extern short g_damagedchannel;
extern char  g_gameplaying;
extern long g_endcut; // end of cut scene
extern char  g_godpower;
#endif

#define INCYBERSPACE ((g_currentscenenumber > SC_GRWALL) ? TRUE : FALSE)
